package com.jan.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

public class TcpServer
{
  private static Map<String,ClientConnecttionThread> clients;
  private TcpServer(){}
  public static void start() throws IOException{
    ServerSocket ssocket=new ServerSocket(1314);
    clients=new HashMap<String,ClientConnecttionThread>();
    while(true){
      Socket socket=ssocket.accept();
      System.out.println("from "+socket.getRemoteSocketAddress().toString());
      ClientConnecttionThread cc=new ClientConnecttionThread(socket);
      Thread conn=new Thread(cc);
      conn.start();
    }
  }
  public static void addClient(String id,ClientConnecttionThread conn){
    clients.put(id, conn);
  }
  public static ClientConnecttionThread getClient(String id){
    return clients.get(id);
  }
}
